package com.biz.primus.ms.depot.api;

import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.model.depot.vo.*;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.depot.service.QrCodeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * QrCodeApiController
 *
 * @author JKLiues
 * @date 2017年11月07日
 */
@RestController
@RequestMapping("soa/qrCodeService")
public class QrCodeApiController extends BaseApiController {

    private final QrCodeService qrCodeService;

    @Autowired
    public QrCodeApiController(QrCodeService qrCodeService) {
        this.qrCodeService = qrCodeService;
    }

    @ApiOperation(value = "后台分页查询二维码列表")
    @PostMapping("pageResult")
    public SpringPageVO<QrCodeBackendListRespVo> pageResult(@RequestBody QrCodeBackendPageReqVo reqVo) {
        return qrCodeService.pageResult(reqVo);
    }

    @ApiOperation("后台更新或新增二维码")
    @PostMapping("save")
    public void save(@RequestBody QrCodeUpdateVo reqVo) {
        qrCodeService.save(reqVo);
    }

    @ApiOperation("后台获取二维码详情配置")
    @GetMapping("detail")
    public QrCodeUpdateVo detail(@ApiParam(value = "二维码ID") @RequestParam("id") Long id) {
        return qrCodeService.detail(id);
    }

    @ApiOperation("后台删除二维码")
    @GetMapping("disable")
    public void disable(@ApiParam(value = "二维码ID") @RequestParam("id") Long id) {
        qrCodeService.disable(id);
    }

    @ApiOperation("后台手动同步当前生效的二维码")
    @GetMapping("sync")
    public void sync() {
        qrCodeService.sync();
    }

    @ApiOperation("前端获取当前生效的二维码")
    @GetMapping("getAllEffective")
    public List<QrCodeListRespVo> getAllEffective() {
        return qrCodeService.getAllEffective();
    }

    @ApiOperation("处理微信推送事件")
    @PostMapping("handleWeChatEvent")
    public void handleWeChatEvent(@RequestBody WeChatEventVo vo) {
        qrCodeService.handleWeChatEvent(vo);
    }
}